<template>
  <view class="help-res">
    <view class="help-res-box">
      <image class="success-icon" :src="success" />
      <view class="help-res-lq"> {{ name }}已成功登记{{ packageInfo.packageName }} </view>

      <view class="help-res-watch-info" @click="watchInfo">查看服务详情</view>
    </view>

    <view v-if="sandingType" class="help-res-box">
      <view class="help-res-sd">
        {{ packageInfo.serviceName }}已进入<text style="color: #f25559">审核阶段</text>，
        审核通过后将于次月1日进行投保。请尽快确认送药信息，避免影响投保审核。
      </view>
      <view class="confirmNow" @click="sendDrug">马上确认</view>
    </view>

    <view v-if="healthType" class="help-res-box">
      <view class="help-res-lq" style="margin-top: 0rpx"> {{ healthName }}已经生效 </view>
      <view class="help-res-lq" style="margin-top: 0rpx"> 欢迎使用 </view>
      <view class="confirmNow experience" @click="health">开始体验</view>
    </view>
  </view>
</template>

<script>
/**
 * 进入页面需要传递: 服务包ID + 受益人ID
 */
import { products } from '@/api/drugInfo';
import { getUserInfoByPatientId } from '@/api/join';
import success from '@/static/icon/success.png';
export default {
  data() {
    return {
      packageId: '',
      insuredId: '',
      orderId: '',
      packageInfo: {
        packageName: '', // 服务包名称
        serviceName: '' // 保险名称
      },
      name: '',
      sandingType: false, // 是否包含三定
      healthName: '', // 智能健康名字
      healthType: false, // 是否有智能健康
      success
    };
  },

  onLoad(opt) {
    // 服务包ID + 受益人ID + 服务单ID

    /* **************************** */
    if (opt) {
      this.packageId = opt ? opt.packageId : '';
      this.insuredId = opt ? opt.insuredId : '';
      this.orderId = opt ? opt.orderId : '';

      this.init();
    } else {
      uni.showModal({
        content: '参数错误',
        showCancel: false
      });
      // this.packageId = 112;
      // this.insuredId = 'a810a061727441c890c1feeb6cf74dd4';

      // this.init();
    }
  },

  methods: {
    async init() {
      uni.showLoading({
        title: '加载中',
        mask: true
      });
      // [被保人信息, 服务包信息]
      const [{ data: _insured }, { data: _packg }] = await Promise.all([
        getUserInfoByPatientId(this.insuredId),
        products(this.packageId)
      ]);
      this.name = _insured.name;
      this.packageInfo = _packg[0];
      if (this.packageInfo.insurancePackagePros && this.packageInfo.insurancePackagePros[0].insuranceServices) {
        this.packageInfo.insurancePackagePros[0].insuranceServices.forEach((item) => {
          if (item.type === 1) {
            this.packageInfo.serviceName = item.serviceName;
          } else if (item.type === 8) {
            this.sandingType = true;
          } else if (item.type === 3) {
            this.healthType = true;
            this.healthName = item.serviceName; // 健康管理入口
          }
        });
      }
      uni.hideLoading();
    },

    // 查看服务详情
    watchInfo() {
      uni.reLaunch({
        // url: '/pages/service/index?patientId=' + this.insuredId
        url: '/pages/index/index?patientId=' + this.insuredId
      });
    },

    // 三定引导
    sendDrug() {
      const params = `insuredPatientId=${this.insuredId}&orderId=${this.orderId}`;
      this.$wxPromise.navigateTo({
        url: '/pages/deliveryService/index?' + params
      });
    },

    // 健康问询
    health() {
      this.$wxPromise.navigateTo({
        url: '/pagesB/assessSick/index?patientId=' + this.insuredId
      });
    }
  }
};
</script>

<style lang="scss">
.help-res {
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  .success-icon {
    width: 56rpx;
    height: 56rpx;
  }
  &-box {
    background: #ffffff;
    margin: 24rpx;
    border-radius: 24rpx;
    padding: 32rpx;
    font-size: 36rpx;
    text-align: center;
  }
  &-gx {
    font-size: 48rpx;
    margin: 12rpx 0;
  }
  &-lq {
    font-size: 36rpx;
    font-weight: 500;
    margin-top: 20rpx;
  }
  &-sd {
    font-size: 32rpx;
    margin-top: 20rpx;
  }
  &-watch-info {
    font-size: 28rpx;
    color: #2680eb;
    margin-top: 20rpx;
  }
  .confirmNow {
    font-size: 32rpx;
    color: #f34e1c;
    border-radius: 44rpx;
    width: 240rpx;
    height: 66rpx;
    line-height: 66rpx;
    border: 1px solid #f34e1c;
    margin: 38rpx auto 10rpx;
  }
  .experience {
    background: linear-gradient(236deg, #fe894d 0%, #ef3931 100%);
    color: #ffffff;
    border: none;
    height: 68rpx;
    line-height: 68rpx;
  }
}
</style>
